﻿using GetSlaughterItem.API.Application.Commands.Week02.LiveAnimalsa;
using MediatR;
using SlaughterItem.Common.Domains.Check_Ins;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    public class LiveAnimalsShowtwosHandler : IRequestHandler<LiveAnimalsShow2Command, Result>
    {

        IBaseRepositoryGet<LiveAnimals> LiveAnimalsRep;

        public LiveAnimalsShowtwosHandler(IBaseRepositoryGet<LiveAnimals> liveAnimalsRep)
        {
            LiveAnimalsRep = liveAnimalsRep;
        }

        public async Task<Result> Handle(LiveAnimalsShow2Command request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };

            try
            {
                var list = LiveAnimalsRep.GetAll().ToList();
                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "查询成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }

}
